﻿using AutoMapper;
using SXICE.Core.Domains;
using SXICE.Core.Infrastructure;
using SXICE.Core.Models;
using SXICE.Core.Models.DTOs;
using SXICE.IService.Models;
using SXICE.WebAPI.Models.DTOs;
using SXICE.WebAPI.Utilities;

namespace SXICE.WebAPI.Infrastructure
{
    /// <summary>
    /// AutoMapper
    /// </summary>
    public class MapperProfile : Profile, IMapperRegister
    {
        /// <summary>
        /// 映射
        /// </summary>
        public MapperProfile()
        {
            #region Customer

            CreateMap<PhonePassword, Customer>();
            CreateMap<PhoneRegister, Customer>().ForMember(c => c.OpenId, opt =>
            {
                opt.MapFrom((s, d) => s.Code);
            });
            CreateMap<PhoneCaptcha, Customer>();
            CreateMap<CustomerUpdate, Customer>().AfterMap((s, d) =>
            {
                d.Id = WorkContext.Customer.Id;
            });

            #endregion

            #region HDAARM

            CreateMap<Models.DTOs.HDAARMSearch, SXICE.IRepository.Models.HDAARMSearch>().AfterMap((s, d) =>
            {
                d.Customer = WorkContext.Customer.Id;
            });

            #endregion
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="mapperConfiguration">接口参数</param>
        public void Register(IMapperConfigurationExpression mapperConfiguration)
        {
            mapperConfiguration.AddProfile<MapperProfile>();
        }
    }
}
